package com.example.hellodemo.recyclerView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hellodemo.R;
import com.example.hellodemo.listView.GrideViewActivity;

public class GrideCyclerViewAdapter extends RecyclerView.Adapter<GrideCyclerViewAdapter.GrideViewHolder> {

    private Context context;
    private ItemClick itemClick;
    public GrideCyclerViewAdapter(Context context , ItemClick itemClick){
        this.context = context;
        this.itemClick = itemClick;


    }
    @NonNull
    @Override
    public GrideCyclerViewAdapter.GrideViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new GrideViewHolder(LayoutInflater.from(context).inflate(R.layout.gride_cycleview_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull GrideCyclerViewAdapter.GrideViewHolder holder, final int position) {
            holder.titleView.setText("GrideView");
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClick.onClick(position);
                }
            });
    }

    @Override
    public int getItemCount() {
        return 20;
    }


    class  GrideViewHolder extends RecyclerView.ViewHolder{
        private TextView titleView;
        public GrideViewHolder(View itemView){
            super(itemView);
            titleView = itemView.findViewById(R.id.gridetitle);

        }
    }
    interface ItemClick{
        public void onClick(int position);
    }

}
